package com.fuda.trade.model
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions

class TradeStrategyUnitTest {
    @Test
    fun deserializeListIsCorrect() {
        val jsonString = """
      [{"id":{"tb":"trade_strategy","id":{"String":"strategy.5.1"}},"klt":"M005","seqno":1,"name":"15分钟K线的1号交易策略","desc":"15分钟K线的1号交易策略","script_verified":true,"script":null,"kl_window":null,"indicators":null,"malines":null,"is_online":null,"is_gen_auto_trade_command":false,"data":{"type":"com.fuda.trade.model.TradeStrategyData.Short","volume":500,"desc":"short@mod.rs"},"last_updated":null},
      {"id":{"tb":"trade_strategy","id":{"String":"strategy.5.2"}},"klt":"M005","seqno":1,"name":"60分钟K线的1号交易策略","desc":"60分钟K线的1号交易策略","script_verified":true,"script":null,"kl_window":null,"indicators":null,"malines":null,"is_online":null,"is_gen_auto_trade_command":false,"data":{"type":"com.fuda.trade.model.TradeStrategyData.Short","volume":500,"desc":"short@mod.rs"},"last_updated":null},
      {"id":{"tb":"trade_strategy","id":{"String":"strategy.5.3"}},"klt":"M005","seqno":1,"name":"日K线的1号交易策略","desc":"日K线的1号交易策略","script_verified":true,"script":null,"kl_window":null,"indicators":null,"malines":null,"is_online":null,"is_gen_auto_trade_command":false,"data":{"type":"com.fuda.trade.model.TradeStrategyData.Long","volume":500,"desc":"long@mod.rs"},"last_updated":null}]
    """.trimIndent()


        // Parse the JSON array into a list of TradeStrategy objects
        val tradeStrategies = TradeStrategy.deserializeList(jsonString)
        Assertions.assertEquals(tradeStrategies.size, 3)

        when (val data:TradeStrategyData? = tradeStrategies[2].data){
            is TradeStrategyData.Long -> Assertions.assertEquals(data.volume,500)
            else -> Assertions.assertEquals(true,false)
        }
    }
}